package com.example.hxds.dr.config;

import com.example.hxds.common.exception.HxdsException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ExceptionAdvice {

    @ResponseBody
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(Exception.class)
    public Exception exceptionHandler(Exception e) {
        //处理业务异常
        if (e instanceof HxdsException) {
            String msg = ((HxdsException) e).getMsg();
            log.error("业务执行异常：{}", msg);
            return e;
        }
        return new Exception();
    }

}